<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Cache-control" content="no-cache" />
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />

    <script type="text/javascript" src="YljSdk.js"></script>

    <script type="text/javascript">
    
    const config = (window.YljShellApp != undefined && YljAdSdk.osType() == "android")?{
        cpId:'191247835488325',
        appId:'191278984306821',
        channel:'demo-xiaomi',
        debug:true,

        intertAdid:'191279360921797',
        splashAdId:'191279118553285',
        fullScreenAdId:'191279417995461',
        rewardAdId:'191279261184197'
    }:{
        cpId:'191247835488325',
        appId:'276849909293189',
        channel:'iOS',
        debug:true,

        intertAdid:'276850232066245',
        splashAdId:'276850050248901',
        fullScreenAdId:'276850268471493',
        rewardAdId:'276850147532997'
    };

//sdk初始化
function sdkInit(){
    YljAdSdk.init(config.cpId, config.appId, config.channel, config.debug);
}

//开屏广告
function splashAd() {
    YljAdSdk.splashAd(config.splashAdId, function(name, data){
        if('onLoadSuccess' == name) {
            YljAdSdk.info('sdk_flow', '开屏加载成功!!');
            return ;
        }

        if('onLoadFailed' == name) {
            YljAdSdk.info('sdk_flow', `开屏加载失败!!, 错误码 : ${data.errorCode}, 错误消息 : ${data.errorMsg}`);
            return ;
        }

        if('onShowSuccess' == name) {
            YljAdSdk.info('sdk_flow', '开屏展示成功!!');
            return ;
        }

        if('onShowFailed' == name) {
            YljAdSdk.info('sdk_flow', `开屏展示失败!!, 错误码 : ${data.errorCode}, 错误消息 : ${data.errorMsg}`);
            return ;
        }

        if('onAdClosed' == name) {
            YljAdSdk.info('sdk_flow', '开屏关闭!!');
            return ;
        }

        if('onAdClicked' == name) {
            YljAdSdk.info('sdk_flow', '用户点击广告!!');
            return ;
        }

        if('onTimeOver' == name) {
            YljAdSdk.info('sdk_flow', '倒计时结束!!');
            return ;
        }

        if('onSkip' == name) {
            YljAdSdk.info('sdk_flow', '用户点击跳过!!');
            return ;
        }
    }, 5000);
}

//插屏广告
function interstitialAd() {
    YljAdSdk.interstitialAd(config.intertAdid, function(name, data){
        if('onLoadSuccess' == name) {
            YljAdSdk.info('sdk_flow', '插屏加载成功!!');
            return ;
        }

        if('onLoadFailed' == name) {
            YljAdSdk.info('sdk_flow', `插屏加载失败!!, 错误码 : ${data.errorCode}, 错误消息 : ${data.errorMsg}`);
            return ;
        }

        if('onShowSuccess' == name) {
            YljAdSdk.info('sdk_flow', '插屏展示成功!!');
            return ;
        }

        if('onShowFailed' == name) {
            YljAdSdk.info('sdk_flow', `插屏展示失败!!, 错误码 : ${data.errorCode}, 错误消息 : ${data.errorMsg}`);
            return ;
        }

        if('onAdClosed' == name) {
            YljAdSdk.info('sdk_flow', '插屏关闭!!');
            return ;
        }

        if('onAdClicked' == name) {
            YljAdSdk.info('sdk_flow', '用户点击广告!!');
            return ;
        }

        if('onVideoStart' == name) {
            YljAdSdk.info('sdk_flow', '视频开始播放!!');
            return ;
        }

        if('onVideoComplete' == name) {
            YljAdSdk.info('sdk_flow', '视频开始播放结束!!');
            return ;
        }
    });
}


//全屏视频广告
function fullScreenAd() {
    YljAdSdk.fullScreenAd(config.fullScreenAdId, function(name, data){
        if('onLoadSuccess' == name) {
            YljAdSdk.info('sdk_flow', '全屏加载成功!!');
            return ;
        }

        if('onLoadFailed' == name) {
            YljAdSdk.info('sdk_flow', `全屏加载失败!!, 错误码 : ${data.errorCode}, 错误消息 : ${data.errorMsg}`);
            return ;
        }

        if('onShowSuccess' == name) {
            YljAdSdk.info('sdk_flow', '全屏展示成功!!');
            return ;
        }

        if('onShowFailed' == name) {
            YljAdSdk.info('sdk_flow', `全屏展示失败!!, 错误码 : ${data.errorCode}, 错误消息 : ${data.errorMsg}`);
            return ;
        }

        if('onAdClosed' == name) {
            YljAdSdk.info('sdk_flow', '全屏关闭!!');
            return ;
        }

        if('onAdClicked' == name) {
            YljAdSdk.info('sdk_flow', '全屏用户点击广告!!');
            return ;
        }
    });
}


//激励视频广告
function rewardAd() {
    let getReward = false;
    YljAdSdk.rewardAd(config.rewardAdId, function(name, data){
        if('onLoadSuccess' == name) {
            YljAdSdk.info('sdk_flow', '激励视频加载成功!!');
            return ;
        }

        if('onLoadFailed' == name) {
            YljAdSdk.info('sdk_flow', `激励视频加载失败!!, 错误码 : ${data.errorCode}, 错误消息 : ${data.errorMsg}`);
            return ;
        }

        if('onShowSuccess' == name) {
            YljAdSdk.info('sdk_flow', '激励视频展示成功!!');
            return ;
        }

        if('onShowFailed' == name) {
            YljAdSdk.info('sdk_flow', `激励视频展示失败!!, 错误码 : ${data.errorCode}, 错误消息 : ${data.errorMsg}`);
            return ;
        }

        if('onAdClosed' == name) {
            YljAdSdk.info('sdk_flow', '激励视频关闭!!');

            if(getReward) {
                YljAdSdk.info('sdk_flow', '奖励发放');
            }else{
                YljAdSdk.info('sdk_flow', '奖励没有发放');
            }
            return ;
        }

        if('onAdClicked' == name) {
            YljAdSdk.info('sdk_flow', '激励视频用户点击广告!!');
            return ;
        }

        if('onReward' == name) {
            YljAdSdk.info('sdk_flow', '激励视频用户奖励!!');
            getReward = true;
            return ;
        }

        if('onSkip' == name) {
            YljAdSdk.info('sdk_flow', '激励视频用户点击跳过!!');
            return ;
        }

    }, "test_user", {
        orderId:'0123456',
        innerOrderId:'9876540'
    });
}

function isAppRuntime() {
    const isInApp = AppExt.nativeMethod("inApp");
    alert(`runtime in app : ${isInApp}`);
}

</script>

</head>
<body>

<p style="margin-top:100px;"></p>

<button onclick="sdkInit()">初始化</button>
<button onclick="splashAd()">开屏</button>
<button onclick="interstitialAd()">插屏</button>
<button onclick="rewardAd()">激励视频</button>
<button onclick="fullScreenAd()">全屏视频</button>

<button onclick="isAppRuntime()">运行环境</button>
<br><br>
<hr>
</body>
</html>